package slash.entities;

import org.newdawn.slick.*;
import org.newdawn.slick.geom.Ellipse;
import slash.collision.CollisionMask;
import slash.constants.Globals;
import slash.util.ControlHandler;


public class Player extends LivingEntity {
	
	ControlHandler controlHandler;
	
	public Player(float x, float y){
		super(x,y);
		/* sets collision mask */
		this.setCollisionMask(new CollisionMask(new Ellipse(0,0,8,5),this));
		this.getCollisionMask().setOffSet(0, 5);
		/* sets starting player animation as down facing animation */
		this.setCurrentAnimation(Globals.ANIMATION_DOWN);
		
		controlHandler = new ControlHandler(this);
		controlHandler.enable();
	}
	
	@Override
	/**
	 * Adds player animations
	 */
	public void initAnimations() throws SlickException {
		int duration = 300;
        
        Animation animation = new Animation(false);
        animation.setLooping(true);
        animation.addFrame(new Image("sprites/player_bk1.gif"), duration);
        animation.addFrame(new Image("sprites/player_bk2.gif"), duration);
        getAnimations().put(Globals.ANIMATION_UP, animation);
        
        animation = new Animation(false);
        animation.setLooping(true);
        animation.addFrame(new Image("sprites/player_fr1.gif"), duration);
        animation.addFrame(new Image("sprites/player_fr2.gif"), duration);
        getAnimations().put(Globals.ANIMATION_DOWN, animation);
        
        animation = new Animation(false);
        animation.setLooping(true);
        animation.addFrame(new Image("sprites/player_lf1.gif"), duration);
        animation.addFrame(new Image("sprites/player_lf2.gif"), duration);
        getAnimations().put(Globals.ANIMATION_LEFT, animation);
        
        animation = new Animation(false);
        animation.setLooping(true);
        animation.addFrame(new Image("sprites/player_rt1.gif"), duration);
        animation.addFrame(new Image("sprites/player_rt2.gif"), duration);
        getAnimations().put(Globals.ANIMATION_RIGHT, animation);
	}

	@Override
	public void update(GameContainer container, int time) {
		super.update(container,time);
		controlHandler.handleInput(container.getInput(), time);
	}

}
